<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        /*
                                                                {
                                                                    var age = 100;
                                                                    var obj = {
                                                                        age: 20,
                                                                        say: function() {
                                                                            alert(this.age) //20
                                                                        }
                                                                    }
                                                                    obj.say()
                                                                }
                                                        */


        // ---------------------------
        {

            var age = 100;
            var obj = {
                age: 20,
                say: () => {
                    // 箭头函数没有this  只与定义的时候有关
                    alert(this.age) //100
                }
            }
            obj.say()

        }

        let a = 'zs';
        let aa = setTimeout(function() {
            console.log(this); //window
            console.log(this.a); //undefined
        }, 1000);


        {
            let a = 'zs';
            let aa = setTimeout(() => {
                console.log(this); //window
                console.log(this.a); //undefined
            }, 1000)
        }
    </script>
</body>

</html>